package com.yc.yyds.dao;

import com.yc.yyds.util.DBHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserQueryMoviesDao {

    //组合条件查询电影
    public Map<String, Object> queryMovies(String name, String type, String area, String date, int begin, int size){
        String sql = "select * from movie where 1 = 1 ";
        List<Object> params = new ArrayList<>();
        if (name!=null && !name.equals("")){
            sql+= " and moviename like ?";
            params.add("%"+name+"%");
        }
        if (type!=null && !type.equals("")&& !type.equals("全部")){
            sql+= " and type like ?";
            params.add(type);
        }
        if (area!=null && !area.equals("")&& !area.equals("全部")){
            sql+= " and area like ?";
            params.add(area);
        }
        if (date!=null && !date.equals("")&& !date.equals("全部")){
            sql+= " and moviedate like ?";
            params.add("%"+date+"%");
        }
        Map<String,Object> map =new HashMap<>();
        long total = DBHelper.count(sql, params.toArray());

        params.add(begin);
        params.add(size);
        List<Map<String, Object>> data = DBHelper.selectListMap(sql + "limit ?, ?", params.toArray());
        map.put("data",data);
        map.put("total",String.valueOf(total).trim());

        return map;
    }

    public List<Map<String,Object>> tuijian(){
        String sql = "select * from movie where tuijian =1";
        return DBHelper.selectListMap(sql);
    }
}
